package me.leon.ext.android

import android.app.ActivityManager
import android.content.Context
import me.leon.ext.Utils.app

fun String.serviceRunning() =
    with(
        (app.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).getRunningServices(
            0x7FFFFFFF
        )
    ) {
        if (this.isNullOrEmpty()) return false
        for (aInfo in this) {
            if (this@serviceRunning == aInfo.service.className) return true
        }
        false
    }

fun <T> Class<T>.serviceRunning() = this.name.serviceRunning()
